import VueRouter from 'vue-router';

import loginManagerRouter from '@/routers/login-router';
import dashboardRouter from '@/routers/dashboard-router';
import userRouter from '@/routers/user-router';
import pagesRouter from '@/routers/pages-router';
import lowerLevelRouter from '@/routers/lower-level-router';
import extensionRouter from '@/routers/extension-router';
import withdrawCenterRouter from '@/routers/withdraw-center-router';
import reportCenterRouter from '@/routers/report-router';
import aboutUsRouter from '@/routers/about-us-router';
import Forbidden from '@/routers/forbidden';

Vue.use(VueRouter);

const addPermission = (routers, metas = {
  needPermission: true,
  header: true,
  footer: true,
}) => {
  return _.map(routers, router => {
    if (router.children) {
      router.children = addPermission(router.children);
    }
    _.each(metas, (value, prop) => {
      _.set(router, `meta.${prop}`, value);
    });
    return router;
  });
};

const router = new VueRouter({
      mode: 'history',
      routes: [
        ...loginManagerRouter,
        ...Forbidden,
        ...addPermission(dashboardRouter),
        ...addPermission(userRouter),
        ...aboutUsRouter,
        ...pagesRouter,
        ...addPermission(lowerLevelRouter),
        ...addPermission(extensionRouter),
        ...addPermission(withdrawCenterRouter),
        ...addPermission(reportCenterRouter)
      ],
    });

export default router;
